//  引入Count的UI组件
import CountUI from '../../components/Redux_react';

// //  引入 store
// import store from '../../redux/store';
import { 
    countIncrementAction,
    countDecrementAction, 
    countIncrementAsyncAction
} from '../../redux/count_action_creator'

// 引入connect 用于连接UI与redux

import { connect } from 'react-redux';

const CountContainer = connect(mapStateToProps,mapDispatchToProps)(CountUI);

/* 
1. mapStateToProps 函数的返回值作为状态传给了UI组件
2. mapStateToProps函数返回的对象中的key就作为传递给UI组件props的key,
value就作为传递给UI组件props的value - 状态 
 */
function mapStateToProps(state) {
    // console.log(state);
    return {
        n: state
    }
};

/*
1. mapDispatchToProps函数返回的对象中的key就作为传递给UI组件props的key,
2. value就作为传递给UI组件props的value - 操作状态的方法
  */
function mapDispatchToProps(dispatch) {
    return {
        jia: (data)=>{
        //    通知redux执行加法
        dispatch(countIncrementAction(data))
        },
        jian: (data) => dispatch(countDecrementAction(data)),

        jiaAsync: (data,time) => dispatch(countIncrementAsyncAction(data,time))
    }
}

/* 

//mapDispatchToProps的简写
{
jia :createIncrementAction,
jian : createDecrementAction,
jiaAsync :createIncrementAsyncAction,
}
*/
export default CountContainer;